import React, { useState } from 'react';
import { IFormItem, Itype } from '@/base-ui/form';
import http from '@/services/request';
import { Space, Button, Select } from 'antd';
import { Input } from 'antd';
import { RightOutlined, UpOutlined } from '@ant-design/icons';

const { Option } = Select;

const { Search } = Input;

/* 搜索区域 */
// 这是高级检索的搜索配置项，一般要和你的表格的列关联
export const PageSearchConfig: IFormItem[] = [
  {
    type: 'input' as Itype,
    label: '所在城市',
    name: 'city',
    placeholder: '请输入请输入所在城市'
  },
  {
    type: 'input' as Itype,
    label: '所属部门名',
    name: 'departmentName',
    placeholder: '请输入所属部门名'
  },
  {
    type: 'input' as Itype,
    label: '详细地址',
    name: 'detailedAddress',
    placeholder: '请输入详细地址	'
  },
  {
    type: 'input' as Itype,
    label: '运营证书',
    name: 'operationCertificateNumber',
    placeholder: '请输入运营证书'
  },
  {
    type: 'input' as Itype,
    label: '站点名称',
    name: 'stationName',
    placeholder: '请输入站点名称'
  },
  {
    type: 'input' as Itype,
    label: '负责人姓名',
    name: 'principalName',
    placeholder: '请输入负责人姓名'
  },
  {
    type: 'input' as Itype,
    label: '负责人电话号码',
    name: 'principalPhone',
    placeholder: '请输入负责人电话号码'
  },

  // {
  //   type: 'input' as Itype,
  //   label: '经过站点数量',
  //   name: 'passStationNumber',
  //   placeholder: '请输入经过站点数量'
  // },
  {
    type: 'input' as Itype,
    label: '负责人id',
    name: 'principalId',
    placeholder: '请输入负责人id'
  },
  {
    type: 'input' as Itype,
    label: '所在省份',
    name: 'province',
    placeholder: '请输入所在省份'
  },
  {
    type: 'input' as Itype,
    label: '所在地区',
    name: 'region',
    placeholder: '请输入所在地区'
  },
  // {
  //   type: 'input' as Itype,
  //   label: '车辆id',
  //   name: 'carId',
  //   placeholder: '请输入车辆id'
  // },
  {
    type: 'input' as Itype,
    label: '备注',
    name: 'remark',
    placeholder: '请输入备注'
  }
];

//高级检索
export const UseSearch = (props: any) => {
  return (
    <Space style={{ float: 'right' }}>
      {props.isMoreSearchShow ? (
        <Button
          type="link"
          size="large"
          onClick={() => {
            props.setisMoreSearchShow(false);
            props.setsearchMore(false);
          }}
        >
          收起
          <UpOutlined />
        </Button>
      ) : (
        <Button
          type="link"
          size="middle"
          onClick={() => {
            props.setisMoreSearchShow(true);
            props.setsearchMore(true);
          }}
        >
          高级检索
          <RightOutlined style={{ marginLeft: '1px' }} />
        </Button>
      )}
    </Space>
  );
};

// 这里是模糊查询 根据xxx进行查询
export const SearchSelector = (props: any) => {
  const [searchid, setsearchid]: any = useState('driverName');
  return (
    <div
      style={{
        display: 'inline-block',
        width: '380px',
        marginBottom: 10,
        marginRight: 10,
        float: 'right'
      }}
    >
      <Select
        defaultValue={Options[1].label}
        style={{ width: 100 }}
        defaultActiveFirstOption
        onSelect={(value: string, option: any) => {
          setsearchid(option.key);
        }}
      >
        {Options.map((i) => (
          <Option value={i.label} key={i.value} children={null} />
        ))}
      </Select>
      <Search
        placeholder="请输入您要查的数据"
        onSearch={(e) => {
          // console.log(e);
          // console.log(searchid);
          if (e.trim() === '') {
            http.get('/logistics/stationLogistics/list/1/10').then((res) => {
              props.dataSource(res.data.records);
            });
            return;
          }
          switch (searchid) {
            case 'operationCertificateNumber': {
              http(`/logistics/stationLogistics/list/operationCertificateNumber/${e}`).then(
                (res) => {
                  props.dataSource(res.data);
                }
              );
              break;
            }
            case 'principalName': {
              http(`/logistics/stationLogistics/list/principalName/${e}`).then(
                (res) => {
                  props.dataSource(res.data);
                }
              );
              break;
            }
            case 'departmentName': {
              http(`/logistics/stationLogistics/list/departmentName/${e}`).then(
                (res) => {
                  props.dataSource(res.data);
                }
              );
              break;
            }
            default: {
              break;
            }
          }
        }}
        style={{ width: '280px' }}
        enterButton
      />
    </div>
  );
};
export const Searchdow = () => {
  return;
};

const Options = [
  { label: '运营证书号', value: 'operationCertificateNumber', onClick: (e: any) => {} },
  { label: '负责人姓名', value: 'principalName', onClick: (e: any) => {} },
  { label: '所属部门名', value: 'departmentName', onClick: (e: any) => {} }
];

/* 表格区域 */

//复选框的接口
export interface DataType {
  id: number;
  key: React.Key;
  name: string;
  age: number;
  address: string;
}
